import sys
import importlib
importlib.reload(sys)
# sys.setdefaultencoding('utf8')

'''
selenium+webdriver进行UI自动化
'''
from selenium import webdriver
from selenium.webdriver.common.proxy import ProxyType
import time
options = webdriver.ChromeOptions()

#设置浏览器header
# options.add_argument('User-Agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36')
# options.add_argument('cookie=MONITOR_WEB_ID=3e935756-5180-45d2-9055-2a0b0f4e0ac9; _ga=GA1.2.667347664.1649817385; _gid=GA1.2.1277516393.1649817385; _tea_utm_cache_2608=undefined; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25227085911682774763021%2522%252C%2522user_unique_id%2522%253A%25227085911682774763021%2522%252C%2522timestamp%2522%253A1649817386270%257D; passport_csrf_token=0b9a3af381a65cc136da49b5938742c1; passport_csrf_token_default=0b9a3af381a65cc136da49b5938742c1; n_mh=MmXC6X3cAURMtoNYdh9gViSBYYpSdXNnKyCfaFmkQxs; sid_guard=92b4b7e0143b525b6fd827d95e037bd9%7C1649817443%7C5184000%7CSun%2C+12-Jun-2022+02%3A37%3A23+GMT; uid_tt=471a258b215d0053fcace1f818959e9e; uid_tt_ss=471a258b215d0053fcace1f818959e9e; sid_tt=92b4b7e0143b525b6fd827d95e037bd9; sessionid=92b4b7e0143b525b6fd827d95e037bd9; sessionid_ss=92b4b7e0143b525b6fd827d95e037bd9; sid_ucp_v1=1.0.0-KDc0MmNjMjRiOTgzNWExZGI5Y2I2NzEwZTk3MGE2M2FlMzljYTQzMGMKFginpoC0goyKBBDj7tiSBhiwFDgIQAsaAmxmIiA5MmI0YjdlMDE0M2I1MjViNmZkODI3ZDk1ZTAzN2JkOQ; ssid_ucp_v1=1.0.0-KDc0MmNjMjRiOTgzNWExZGI5Y2I2NzEwZTk3MGE2M2FlMzljYTQzMGMKFginpoC0goyKBBDj7tiSBhiwFDgIQAsaAmxmIiA5MmI0YjdlMDE0M2I1MjViNmZkODI3ZDk1ZTAzN2JkOQ')
# browser = webdriver.Chrome(executable_path = r"C:\Program Files\Google\Chrome\Application\chromedriver.exe", chrome_options = options)

browser = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chromedriver.exe")
# proxy=webdriver.Proxy()
# proxy.proxy_type=ProxyType.MANUAL
# proxy.http_proxy='127.0.0.1:8888'
#
# # 将代理设置添加到webdriver.DesiredCapabilities.PHANTOMJS中
# proxy.add_to_capabilities(webdriver.DesiredCapabilities.PHANTOMJS)
# browser.start_session(webdriver.DesiredCapabilities.PHANTOMJS)
browser.get('https://juejin.cn/user/center/signin?from=avatar_menu')
browser.add_cookie("MONITOR_WEB_ID=3e935756-5180-45d2-9055-2a0b0f4e0ac9; _ga=GA1.2.667347664.1649817385; _gid=GA1.2.1277516393.1649817385; _tea_utm_cache_2608=undefined; __tea_cookie_tokens_2608=%257B%2522web_id%2522%253A%25227085911682774763021%2522%252C%2522user_unique_id%2522%253A%25227085911682774763021%2522%252C%2522timestamp%2522%253A1649817386270%257D; passport_csrf_token=0b9a3af381a65cc136da49b5938742c1; passport_csrf_token_default=0b9a3af381a65cc136da49b5938742c1; n_mh=MmXC6X3cAURMtoNYdh9gViSBYYpSdXNnKyCfaFmkQxs; sid_guard=92b4b7e0143b525b6fd827d95e037bd9%7C1649817443%7C5184000%7CSun%2C+12-Jun-2022+02%3A37%3A23+GMT; uid_tt=471a258b215d0053fcace1f818959e9e; uid_tt_ss=471a258b215d0053fcace1f818959e9e; sid_tt=92b4b7e0143b525b6fd827d95e037bd9; sessionid=92b4b7e0143b525b6fd827d95e037bd9; sessionid_ss=92b4b7e0143b525b6fd827d95e037bd9; sid_ucp_v1=1.0.0-KDc0MmNjMjRiOTgzNWExZGI5Y2I2NzEwZTk3MGE2M2FlMzljYTQzMGMKFginpoC0goyKBBDj7tiSBhiwFDgIQAsaAmxmIiA5MmI0YjdlMDE0M2I1MjViNmZkODI3ZDk1ZTAzN2JkOQ; ssid_ucp_v1=1.0.0-KDc0MmNjMjRiOTgzNWExZGI5Y2I2NzEwZTk3MGE2M2FlMzljYTQzMGMKFginpoC0goyKBBDj7tiSBhiwFDgIQAsaAmxmIiA5MmI0YjdlMDE0M2I1MjViNmZkODI3ZDk1ZTAzN2JkOQ")
browser.find_element_by_class_name('signin btn')[0].click()
# browser.find_element_by_id("kw").send_keys(u"四大名著")
# browser.find_element_by_id("su").click()
# time.sleep(2)
# browser.quit()